C# SDK

C#

Here's an example of calling an API method from AltaPay's C# SDK:

private Stream CallApi(string method, Dictionary<string,Object> parameters)
{
	WebRequest request = WebRequest.Create(String.Format("{0}{1}", _gatewayUrl, method));
	request.Credentials = new NetworkCredential(_username, _password);
	HttpWebRequest http = (HttpWebRequest)request;
	http.Method = "POST";
	http.ContentType = "application/x-www-form-urlencoded";
	http.Headers.Add("x-altapay-client-version", String.Format("C#SDK/{0}", GetSdkVersion()));
	string encodedData = ParameterHelper.Convert(parameters);
	Byte[] postBytes = System.Text.Encoding.ASCII.GetBytes(encodedData);
	http.ContentLength = postBytes.Length;
	Stream requestStream = request.GetRequestStream();
	requestStream.Write(postBytes, 0, postBytes.Length);
	requestStream.Close();
	WebResponse response = request.GetResponse();
	return response.GetResponseStream();
}